﻿namespace SupportSystemUI.Controls.CustomPages.Crew
{
    using System.Windows.Controls;
    using System.Windows.Media;
    using SupportSystemDB;
    using SupportSystemUI.Controls.Pages;

    /// <summary>
    /// Interaction logic for Working Year.xaml
    /// </summary>
    public partial class YearItem : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="YearItem"/> class.
        /// </summary>
        /// <param name="year">The year string of this control in the form of "'XX" (example: "'09").</param>
        /// <param name="events">The events this year.</param>
        /// <param name="generalHighboard">The general high board names of this year.</param>
        public YearItem(string year, string events, string generalHighboard)
        {
            this.InitializeComponent();

            this.yearBlockDark.Content = this.yearBlockLight.Content = "'" + year.Substring(2, 2);
            this.eventsBlock.Text = events;
            this.ghbBlock.Text = generalHighboard;

            this.MouseEnter += (sender, args) =>
            {
                this.Background = new SolidColorBrush(Color.FromRgb(240, 240, 240));
            };
            this.MouseLeave += (sender, args) =>
            {
                this.Background = new SolidColorBrush(Colors.White);
            };
            this.MouseUp += (sender, args) =>
            {
                Global.Instance.PagesScreen.Push(
                    () => AppController.Instance.Events.GetInYear(int.Parse(year)),
                    EventItem.View);
            };
        }

        /// <summary>
        /// Returns the data needed to display the crew page.
        /// </summary>
        /// <returns>A dynamic object with the properties Year, Event, and GHB.</returns>
        public static object Model()
        {
            return new dynamic[]
            {
                new { Year = "2009", Event = "SUPPORT Academy", GHB = "Yasser Ashour, Yassin Elwakeel, and Magdy Medhat" },
                new { Year = "2010", Event = "Career Key", GHB = "Yasser Ashour, Yassin Elwakeel, and Magdy Medhat" },
                new { Year = "2011", Event = "SUPPORT Technology Day", GHB = "Kareem Elgebaly, Mariam Elghoneimy, and Khaled Abdel Bary" },
                new { Year = "2012", Event = "Suppology & UEarn", GHB = "Mostafa Gaber, Ahmed Karam, and Amr Hosni" },
                new { Year = "2013", Event = "Coming Soon", GHB = "Soliman Elmasry, Ahmed Karam, and Asmaa Mariee" },
            };
        }

        /// <summary>
        /// Returns the control filled with the provided data.
        /// </summary>
        /// <param name="data">Data object to use.</param>
        /// <returns>A PageData object.</returns>
        public static PageData View(object data)
        {
            StackPanel panel = new StackPanel();
            foreach (dynamic item in data as dynamic[])
            {
                panel.Children.Add(new YearItem(item.Year, item.Event, item.GHB));
            }

            return new PageData(panel, "SUPPORT Crew");
        }
    }
}
